<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProductsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->char('unique', 12)->unique()->comment('料号');
            $table->unsignedBigInteger('customer_id')->comment('所属客户');
            $table->string('sku', 150)->comment('产品sku');

            $table->string('barcode', 150)->comment('默认条码');
            $table->string('name')->comment('产品名称');
            $table->double('net_weight', 9, 3)->comment('产品净重');
            $table->double('weight', 9, 3)->comment('产品毛重');
            $table->string('brand', 50)->comment('品牌');

            $table->char('hs_code', 10)->comment('商品编码');
            $table->char('country', 3)->comment('原产国');
            $table->char('unit', 3)->comment('申报单位');
            $table->char('currency', 3)->comment('申报币种');

            $table->string('element', 255)->nullable()->comment('申报要素');
            $table->double('qy1')->nullable()->comment('法定第一数量');
            $table->double('qy2')->nullable()->comment('法定第二数量');

            $table->string('model')->nullable()->comment('型号');
            $table->string('specs')->nullable()->comment('规格');
            $table->string('function')->nullable()->comment('功能');
            $table->string('use')->nullable()->comment('用途');
            $table->string('ingredient')->nullable()->comment('成分');

            $table->tinyInteger('status')->default(0)->comment('状态: 0 草稿; 1 审核; 2 异常; 3 正常; 4 锁定;');
            $table->timestamps();
            $table->unique(['sku', 'customer_id']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
    }
}
